<?php
if(isset($_POST['gpid']))
{
		session_start();
		$gpid = $_POST['gpid'];
		require_once("../connection.php");
		require_once("../../functions.php");
		require_once("../../functions_shared.php");
		$user = $_SESSION['user'];
}
else
require_once("php/connection.php");

//name and members
$res = mysql_query("SELECT * FROM site_groups WHERE `id`='$gpid' AND `del`!='1'");
if(!$res) echo mysql_error();

if(mysql_numrows($res) == 0)
{
	echo '<div class="err_box small-font">No such group exists my friend!</div>';
}
else
{
	$gp_name = mysql_result($res,0,'name');
	$gp_description = mysql_result($res,0,'description');
	
	//checking if the present logged in user is a member or not
	$mem_yon = mysql_numrows(mysql_query("SELECT * FROM site_group_members WHERE `gpid`='$gpid' AND `fbid`='$user' AND `del`!='1'"));
	//checking if the present logged in user is the admin or not
	$admin_yon = mysql_numrows(mysql_query("SELECT * FROM site_groups WHERE `id`='$gpid' AND `fbid`='$user'"));
	//checking if the present logged in user is the mod or not
	$mod_yon = mysql_numrows(mysql_query("SELECT * FROM site_group_members WHERE `gpid`='$gpid' AND `fbid`='$user' AND `mod`='1' AND `del`!='1'"));
	
	echo '<div style="padding:20px;">';
	
	// The name and description
	echo '<table style="width:100%"><tr><td style="width:75%" valign="top">';
	fetch_gp_details($gpid);
   
	 
	echo '<br>';
	//manage circle; edit description and viewability
	if($admin_yon == '1')  // only when the person logged is the admin 
	{
		echo '<br><fieldset> 
		<label>EDIT</label><br><br>';
		 
		echo '<div class="faded">Name: <br>
		<span class="gpid" style="display:none">'.$gpid.'</span>
		<div class="gp_name" style="color:#000">'.$gp_name.'</div>
		<div class="gp_name_edit"></div>
		<span class="a gp_description_edit_link" onclick="edit_gp_name(this,0)">edit</span>
		</div><br>';
		
		echo '</fieldset>';
	}
	
		
	echo '</td><td valign="top">';
	
	// option to leave circle or delete circle
		if($admin_yon== "1" )
		{ 

		echo '<div class="medium-menu" >
		<div class="menu-icon"><img src="images/del.png" /></div>
		<div class="menu-text"><span onclick=\'del_circle('.$gpid.', '.$user.', this, "question")\' class="a">Delete Circle</span></div>
		<div class="clear"></div></div>'; 
		}

	else if($mem_yon == "1")
		{
		echo '<div class="medium-menu" >
		<div class="menu-icon"><img src="images/exit.png" /></div>
		<div class="menu-text"><span onclick=\'leave_circle('.$gpid.', '.$user.', this, "question")\' class="a">Leave Circle</span></div>
		<div class="clear"></div></div>';
		}
	
	echo '</div>';
	echo '</td></tr></table>';
	
	//notification
	// requests
	if($mod_yon == '1' && $gp_visibility!="public")
	{
		$res = mysql_query("SELECT * FROM site_requests WHERE `gpid`='$gpid' AND `status`='0'");
		if(mysql_numrows($res) != 0) 
		echo '<br><strong class="small-font">Add Requests('.mysql_numrows($res).')</strong><br>';
		
		disp_user($res,"requests_".$gpid."",$user);
	}
	
	
	//members of the group
	// its open to anyone 	
	
	if($gp_visibility != "closed" || $mem_yon!=0)	
	{	 
		$res = mysql_query("SELECT * FROM site_group_members WHERE `gpid`='$gpid' AND `del`!='1'");
		
		echo '<br><strong class="small-font">Members ('.mysql_numrows($res).')</strong><br>';	
		disp_user($res,"group_".$gpid."",$user);
	}
	else
		echo '<span class="err_box">You need to be a member to view the members of this group.</span>';
	
	// add people to the group
	
	if($mem_yon!=0)
	{
		echo '<br><strong class="small-font">Add more members</strong><br>';
		echo '<div id="frnd_list">
			<img src="images/22.gif" />
			</div>
			
			<script>
			$(function() {
				show_frnd_list("");
			});
			</script>
			<input type="hidden" id="curr_gpid" value="'.$gpid.'"/>
			<button onclick=\'add_more_members(this)\'>Add</button>
			';
	}
	
	echo '</div><br><Br><br><br>';
	
}

?>	